// pages/zhaoping/zhaoping.js
let animation = wx.createAnimation({
  duration: 4000, //转盘转动时间
  timingFunction: 'ease-out' //动画效果
})
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

    modalHidden: true,
    modalHiddenlin: true,

    POST_IDCARD: '',

    POST_MONEY: '',

    OPEN_ID: '',
    rotate: 0, //度数
    turning: false, //是否点击,

    prize: '', //中奖概率
    count: '', //剩余次数
    prizeList: [
      2100, //一等奖 ...
      2400, //二等奖  ...
      2330, //三等奖...
      2610, //参与奖 ...
      2200, //谢谢惠顾 ...
    ],
    //向1006传递的数据
    USER_PRIZE_ID: '',



    EMPLOYEE_ID: '',
    zhongjiangtu: '',
    flag: true, //设置节流
    flagaa: true, //设置节流

    jiangsj: "",
  },



  wugandenglu() {
    wx.request({
      url: app.globalData.interface+'/xianyang/API_3007_XianYangTomatoRichManLogin',
      method: 'POST',
      data: {
        OPEN_ID: this.data.OPEN_ID, //用户OPEN_ID
        session_key: this.data.session_key,
        OPEN_UUID: this.data.jiami,
        USER_ASSETS_PHONE: this.data.phone,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log('---==', res);
        console.log('---==', res.data.data);

        if (res.data.result == 'error') {
          wx.showModal({
            title: '温馨提示',
            content: res.data.data,
            success: function (res) {
              if (res.confirm) { //这里是点击了确定以后

              } else { //这里是点击了取消以后
                console.log('用户点击取消')
              }
            }
          })
        } else {





          this.setData({
            jiangsj: res.data.data,
          })
          console.log(this.data.ajaj);
        }
      }
    })
  },





























  tishi() {

    wx.showModal({
      title: '温馨提示',
      content: '请去下线任意网点激活领取',
      success: function (res) {
        if (res.confirm) { //这里是点击了确定以后
          console.log('用户点击确定')

        } else { //这里是点击了取消以后
          console.log('用户点击取消')

        }
      }
    })

  },









  back() {
    wx.navigateBack({
      delta: 1
    })
  },






  linqujiekou() {

    let that = this
    if (that.data.flagaa) {
      console.log(111);
      that.data.flagaa = false
      // if (that.data.huodeshuju.PRIZE_ID == '4') {
      //   wx.showModal({
      //     title: '温馨提示',
      //     content: '请去下线任意网点领取',
      //     success: function (res) {
      //       if (res.confirm) { //这里是点击了确定以后
      //         console.log('用户点击确定')
      //       } else { //这里是点击了取消以后
      //         console.log('用户点击取消')
      //       }
      //     }
      //   })
      //   // if (this.data.PRIZE_ID == '5') {
      //   that.setData({
      //     modalHiddenlin: true,
      //   });
      // } else {

        wx.request({
          url: app.globalData.interface+'/xianyang/API_3011_XianYangTomatoRichManRaffleALiPay',
          method: 'POST',
          data: {
            // USER_ASSETS_IDCARD: that.data.STUDENT_PHONE,
            // CUSTOMER_ID: that.data.CUSTOMER_ID,
            USER_PRIZE_ID: that.data.huodeshuju.USER_PRIZE_ID,
            OPEN_ID: that.data.OPEN_ID, //用户OPEN_ID
            session_key: that.data.session_key,
            OPEN_UUID: that.data.jiami
          },
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          success: res => {
            console.log(res);
            wx.showModal({
              title: '温馨提示',
              content: res.data.data,
              success: function (res) {
                if (res.confirm) { //这里是点击了确定以后
                  console.log('用户点击确定')
                  that.setData({
                    modalHiddenlin: true,
                  });
                } else { //这里是点击了取消以后
                  console.log('用户点击取消')
                  that.setData({
                    modalHiddenlin: true,
                  });
                }
              }
            })
          }
        })

      // }
      setTimeout(() => {
        that.data.flagaa = true
      }, 5500)
    }
  },







  //自定义模态框的取消
  modalCancel: function () {
    let animation = wx.createAnimation({
      duration: 100,
      timingFunction: 'ease-out'
    });
    animation.rotate(0).step();
    this.setData({
      modalHidden: true,
      erdeng: true,
      sandeng: true,
      sideng: true,
      xiexie: true,
      rotate: animation.export(),
    })
    console.log(222);
  },

  //自定义模态框的确定
  queding: function () {
    let animation = wx.createAnimation({
      duration: 100,
      timingFunction: 'ease-out'
    });
    animation.rotate(0).step();
    this.setData({
      modalHidden: true,
      erdeng: true,
      sandeng: true,
      sideng: true,
      xiexie: true,
      rotate: animation.export(),
    })
    console.log(111);
  },


  start: function () {
    let that = this
    // 节流
    if (that.data.flag) {

      that.data.flag = false
      wx.request({
        url: app.globalData.interface+'/xianyang/API_3009_XianYangTomatoRichManRaffle',
        method: 'POST',
        data: {
          OPEN_ID: that.data.openid,
          session_key: that.data.session_key,
          OPEN_UUID: that.data.jiami,
          USER_ASSETS_PHONE: that.data.jiangsj.USER_ASSETS_PHONE,
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: res => {
          if (res.data.result == "error") {
            if (res.data.prize.VALID == '1') {
              console.log(11);
              wx.showModal({
                title: '温馨提示',
                content: '您已抽奖请去网点激活领取',
                success: function (res) {
                  if (res.confirm) { //这里是点击了确定以后
                    console.log('用户点击确定')
                  } else { //这里是点击了取消以后
                    console.log('用户点击取消')
                  }
                }
              })
            } else
            if (res.data.prize.VALID == '2') {

              console.log(22);

              that.setData({
                modalHiddenlin: false,
                zhongjiangtu: res.data.prize.STOCK_ID,
                huodeshuju: res.data.prize,
              })
            } else if (res.data.prize.VALID == '3') {
              console.log(11);
              wx.showModal({
                title: '温馨提示',
                content: '您已领取过',
                success: function (res) {
                  if (res.confirm) { //这里是点击了确定以后
                    console.log('用户点击确定')
                  } else { //这里是点击了取消以后
                    console.log('用户点击取消')
                  }
                }
              })

            }

            // else if (res.data.prize.VALID == '4'){
            //   wx.showModal({
            //     title: '温馨提示',
            //     content: '您已领取过',
            //     success: function (res) {
            //       if (res.confirm) { //这里是点击了确定以后
            //         console.log('用户点击确定')
            //       } else { //这里是点击了取消以后
            //         console.log('用户点击取消')
            //       }
            //     }
            //   })
            // }

          } else {


            console.log(res.data);
            that.setData({
              huodeshuju: res.data.prizeMessage,
            })
            setTimeout(() => {
              that.setData({
                modalHidden: false,
                zhongjiangtu: res.data.prizeMessage.STOCK_ID

              })
            }, 5500)
            const index_ = res.data.prizeMessage.PRIZE_ID;

            that.rotate(index_)
          }

        }
      })


      setTimeout(() => {
        that.data.flag = true
      }, 5500)


    }



    // const index_ = 1;

    // this.rotate(index_)
  },

  // 转盘代码
  rotate: function (index_) {
    // rotate: function () {
    let _this = this;
    // let cat = 60;
    if (!this.data.turning) {
      let rdm = 0; //度数
      rdm = Math.floor(Math.random() * 3600); //最大10圈
      // rdm = 2100; //最大10圈
      //用索引的方法对应角度
      rdm = this.data.prizeList[index_ - 1]; //直接确定转的度数 
      // rdm =2200;//直接确定转的度数 
      animation.rotate(rdm).step();
      this.setData({
        rotate: animation.export(),
        turning: true
      });
      setTimeout(() => {
        this.setData({
          turning: false
        });
        let num = rdm % 360; //转了多少度
        //console.log(num);
        function showModal(str) {
          wx.showModal({
            title: '恭喜抽中',
            content: str,
            success: function () { //点击确定后还原到0度
              let animation = wx.createAnimation({
                duration: 100,
                timingFunction: 'ease-out'
              });
              animation.rotate(0).step();
              _this.setData({
                rotate: animation.export(),
                turning: false
              });
            },
            fail: function (res) {
              console.log(res)
            }
          })
        }

        if (rdm == 2200) {
          // showModal('谢谢惠顾');
          this.setData({
            modalHidden: true
          })
        } else if (rdm == 2100) {
          // showModal('一等奖');
          this.setData({
            modalHidden: true
          })
        } else if (rdm == 2330) {
          // showModal('三等奖');
          this.setData({
            modalHidden: true
          })
        } else if (rdm == 2610) {
          // showModal('参与奖');
          this.setData({
            modalHidden: true
          })
        } else if (rdm == 2400) {
          // showModal('二等奖');
          this.setData({
            modalHidden: true
          })
        }
      }, 4500)
    }
  },








  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(option) {
    console.log(option);




    this.setData({

      openid: app.globalData.openid,
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,
      phone: app.globalData.phone,

    });

    console.log(this.data.phone);


    this.wugandenglu()




  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {




  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {


  },



})